<!DOCTYPE html>
<html>
<head>
    <title>E-k Diagram</title>
</head>
<body>
    <canvas id="ekDiagramCanvas" width="600" height="550"></canvas>
    <script>
        const canvas = document.getElementById('ekDiagramCanvas');
        const ctx = canvas.getContext('2d');

        // Style settings
        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';
        ctx.lineWidth = 1.5;
        ctx.font = "16px Arial";
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';

        // Drawing coordinates
        const x0 = 70;
        const y0 = 480;
        const xAxisLength = 480;
        const yAxisLength = 420;
        const yTop = y0 - yAxisLength;

        // Draw axes
        ctx.beginPath();
        // Y-axis
        ctx.moveTo(x0, y0);
        ctx.lineTo(x0, yTop - 10);
        ctx.lineTo(x0 - 5, yTop + 5);
        ctx.moveTo(x0, yTop - 10);
        ctx.lineTo(x0 + 5, yTop + 5);
        // X-axis
        ctx.moveTo(x0, y0);
        ctx.lineTo(x0 + xAxisLength + 20, y0);
        ctx.lineTo(x0 + xAxisLength + 5, y0 - 5);
        ctx.moveTo(x0 + xAxisLength + 20, y0);
        ctx.lineTo(x0 + xAxisLength + 5, y0 + 5);
        ctx.stroke();

        // Axis labels
        ctx.font = "italic 20px 'Times New Roman'";
        ctx.fillText("ε", x0 - 25, yTop + 10);
        ctx.fillText("k", x0 + xAxisLength + 30, y0);
        ctx.font = "16px Arial";

        // X-axis ticks and labels
        const x_pi_a = x0 + xAxisLength;
        const k1_frac = 0.2, k2_frac = 0.35, k3_frac = 0.6, k4_frac = 0.8;
        const x_k1 = x0 + k1_frac * xAxisLength;
        const x_k2 = x0 + k2_frac * xAxisLength;
        const x_k3 = x0 + k3_frac * xAxisLength;
        const x_k4 = x0 + k4_frac * xAxisLength;
        
        ctx.textBaseline = 'top';
        ctx.fillText("0", x0, y0 + 5);
        
        ctx.font = "italic 16px 'Times New Roman'";
        ctx.fillText("k", x_k1, y0 + 5);
        ctx.font = "12px 'Times New Roman'";
        ctx.fillText("1", x_k1 + 8, y0 + 10);

        ctx.font = "italic 16px 'Times New Roman'";
        ctx.fillText("k", x_k2, y0 + 5);
        ctx.font = "12px 'Times New Roman'";
        ctx.fillText("2", x_k2 + 8, y0 + 10);

        ctx.font = "italic 16px 'Times New Roman'";
        ctx.fillText("k", x_k3, y0 + 5);
        ctx.font = "12px 'Times New Roman'";
        ctx.fillText("3", x_k3 + 8, y0 + 10);
        
        ctx.font = "italic 16px 'Times New Roman'";
        ctx.fillText("k", x_k4, y0 + 5);
        ctx.font = "12px 'Times New Roman'";
        ctx.fillText("4", x_k4 + 8, y0 + 10);

        ctx.font = "18px 'Times New Roman'";
        ctx.fillText("π", x_pi_a, y0 + 5);
        ctx.beginPath();
        ctx.moveTo(x_pi_a - 5, y0 + 18);
        ctx.lineTo(x_pi_a + 5, y0 + 18);
        ctx.stroke();
        ctx.font = "italic 18px 'Times New Roman'";
        ctx.fillText("a", x_pi_a, y0 + 22);
        
        // Y-axis energy levels
        const y_eC = y0 - 120;
        const y_eF = y0 - 180;
        const y_eV = y0 - 240;

        ctx.textAlign = 'right';
        ctx.textBaseline = 'middle';
        ctx.font = "italic 18px 'Times New Roman'";
        ctx.fillText("ε", x0 - 15, y_eC);
        ctx.font = "italic 14px 'Times New Roman'";
        ctx.fillText("C", x0 - 10, y_eC + 7);

        ctx.font = "italic 18px 'Times New Roman'";
        ctx.fillText("ε", x0 - 15, y_eF);
        ctx.font = "italic 14px 'Times New Roman'";
        ctx.fillText("F", x0 - 10, y_eF + 7);

        ctx.font = "italic 18px 'Times New Roman'";
        ctx.fillText("ε", x_pi_a + 25, y_eV);
        ctx.font = "italic 14px 'Times New Roman'";
        ctx.fillText("V", x_pi_a + 30, y_eV + 7);

        // Dashed lines
        ctx.setLineDash([5, 5]);
        ctx.lineWidth = 1;
        // Horizontal lines
        ctx.beginPath();
        ctx.moveTo(x0, y_eC);
        ctx.lineTo(x_k1, y_eC);
        ctx.moveTo(x0, y_eF);
        ctx.lineTo(x_pi_a, y_eF);
        ctx.moveTo(x0, y_eV);
        ctx.lineTo(x_pi_a, y_eV);
        ctx.stroke();
        // Vertical lines
        ctx.beginPath();
        ctx.moveTo(x_k1, y0);
        ctx.lineTo(x_k1, y_eC);
        ctx.moveTo(x_k2, y0);
        ctx.lineTo(x_k2, y_eF);
        ctx.moveTo(x_k3, y0);
        ctx.lineTo(x_k3, y_eF);
        ctx.moveTo(x_k4, y0);
        ctx.lineTo(x_k4, y_eV);
        ctx.stroke();
        ctx.setLineDash([]);

        // Draw the energy bands (thick lines)
        ctx.lineWidth = 3;
        ctx.lineCap = 'round';
        ctx.lineJoin = 'round';

        // Lower Band
        ctx.beginPath();
        ctx.moveTo(x0, y0 - 20); // Starts slightly above ε=0
        ctx.bezierCurveTo(x0 + 100, y0 - 120, x_k3 - 80, y_eF + 30, x_k3, y_eF);
        ctx.bezierCurveTo(x_k3 + 50, y_eF - 70, x_k4, y_eV - 50, x_pi_a, y_eV + 20);
        ctx.stroke();
        
        // Upper Band
        ctx.beginPath();
        ctx.moveTo(x0, y_eV-20); // Starts high at k=0
        ctx.quadraticCurveTo(x_k1 - 40, y_eC+10, x_k1, y_eC);
        ctx.bezierCurveTo(x_k2-10, y_eF+50, x_k3, yTop - 20, x_pi_a, yTop + 50);
        ctx.stroke();

        // Brillouin Zone boundary line
        ctx.lineWidth = 1.5;
        ctx.beginPath();
        ctx.moveTo(x_pi_a, y_eV + 20);
        ctx.lineTo(x_pi_a, yTop + 50);
        ctx.stroke();

        // Figure caption
        ctx.lineWidth = 1;
        ctx.textAlign = 'center';
        ctx.textBaseline = 'bottom';
        ctx.font = "16px 'Times New Roman'";
        ctx.fillText("Fig. 1.22", canvas.width / 2, canvas.height - 10);
    </script>
</body>
</html>